<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="l" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*" %>  
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>注册</title>
    
    
    <!-- Favicon -->
    <link rel="shortcut icon" href="img/favicon.ico" />
    
    <!-- CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link href="css/font-awesome.min.css" rel="stylesheet" />
    <link href="css/style.css" rel="stylesheet" />
    
    <!-- Google Fonts -->
    <link href='http://fonts.useso.com/css?family=Titillium+Web' rel='stylesheet' type='text/css'>
	<script type="text/javascript">
	//创建XMLHttpRequest对象
	var xhr;
	function createXHR() {
		if (window.ActiveXObject) {//IE6及以前版本
			xhr = new ActiveXobject("Microsoft.XMLHTTP");
		} else if (window.XMLHttpRequest) {//新的Ie,或者火狐
			xhr = new XMLHttpRequest();
		} else {
			alert("can't create xhr object!");
		}
	}
	//发送异步请求
	function checkUsername() {
		//获取用户名得值
		var nm = document.getElementById("uname").value;
		createXHR();//调用xhr的方法。创建此对象
		//设置回调函数
		xhr.onreadystatechange = callback;//一定要写在open send之前
		/* GET提交方式 */
		//url
		var url ="${pageContext.request.contextPath}/CheckUser.do?user="+nm+"&t="+Math.random();
		
		 //open()连接到服务器，规定请求的类型,url以及是否异步处理请求
		 xhr.open("GET", url);
		//发送
		xhr.send();
	}
	var type=0;
	//定义回调函数，接收服务器返回的数据
	function callback() {
		//判断服务器是否正确响应
		if (xhr.readyState == 4 && xhr.status == 200) {
			//接收返回文本
			var str = xhr.responseText;
			//var obj = document.getElementById("sp_user");
			if (str == "true") {
			document.getElementById("userCue").innerHTML="<font color='red'><b>用户名已存在，不可使用</b></font>";
				
			} else {
			
			document.getElementById("userCue").innerHTML="用户名可以使用";
			type=1;
			}
		}
	}
	</script>
</head>

<body onload="chage()">

    <!-- Start: Preloader -->
    <div id="preloader">
        <div id="loader"></div>
    </div>
    <!-- End: Preloader -->

    <!-- Start: Main Content -->
    <div class="main-container">
        
        <!-- Start: Home -->
        <section class="home-section">
            <div class="container" style="margin-top: 80px">
				<div class="row">
					<div class="col-md-12 col-sm-12 col-xs-12">
						<h1 style="color: FFFFFF">图书商城</h1>
					</div>
				</div>
            </div>
        </section>
        <!-- End: Home -->
		
		<!-- Start: Content -->
        <section class="content-section">
            <div class="container">
				
			
				<div class="row">
					<div class="col-md-12" align="center">
						<h2 class="page-header"><span>欢迎注册</span></h2>
					</div>
					<div class="col-xs-12">
						<div class="" align="center">
							<form role="form" action="Register.do" method="post" name="channelform" onsubmit="return validate_channel_info(this);">
							<div id="userCue" class="cue"></div>
								<div class="form-group" align="center" style="padding-top: 40px" id="userCue">
									<label for="exampleInputEmail1">用户名</label>
									<input type="text" name="uname" class="form-control" id="uname"  style="width: 300" onblur="checkUsername();">
								</div>
								<div class="form-group" align="center">
									<label for="exampleInputPassword1">密码</label>
									<input type="password" name="password" class="form-control"  style="width: 300">
								</div>
								<div class="form-group" align="center">
									<label for="exampleInputPassword1">确认密码</label>
									<input type="password" name="password1" class="form-control"  style="width: 300">
								</div>
								<div class="form-group" align="center">
									<label for="exampleInputEmail1">邮箱</label>
									<input type="email" name="email" class="form-control" style="width: 300">
								</div>
								<div class="form-group" align="center">
									<label for="exampleInputEmail1">身份证号</label>
									<input type="text" name="IDnumber" class="form-control" style="width: 300">
								</div>
								<div class="form-group" align="center">
									<label for="exampleInputEmail1">联系方式</label>
									<input type="text" name="phone" class="form-control" style="width: 300">
								</div>
								
								<div class="form-group" align="center">
									<label for="exampleInputEmail1">邮编</label>
									<input type="text" name="postcode" class="form-control" style="width: 300">
								</div>
								<div class="form-group" align="center">
									<label for="exampleInputEmail1">地址</label>
									<input type="text" name="address" class="form-control" style="width: 300">
								</div>
								
								<br/>
								<button type="submit" class="btn btn-primary-alt">注册</button>
							</form>
							<button onclick="window.open('login_user.jsp')" class="btn btn-primary-alt">返回登录</button>
						</div>
					</div>
				<script  type="text/javascript">
					 function  chage(){
						document.getElementById("userCue").innerHTML="快速注册请注意格式";
					 }
					 function validate_channel_info(channelform)  
			                    {  
			                        if((channelform.uname.value=="")||(!isName(channelform.uname.value)))  
			                        {  
			                            alert("请输入字母开头，长度为5-16，允许字母数字下划线的字符");  
			                            return false;  
			                        }  
			                        else if((channelform.password.value=="")||((channelform.password.value).length<6))  
			                        {  
			                            alert("请填写至少6位长度密码");  
			                            return false;  
			                        }
			                        else if(channelform.password1.value!=channelform.password.value)  
			                        {  
			                            alert("密码有误，请填写相同的密码");  
			                            return false;  
			                        }
			               			else if(channelform.email.value=="")  
			                        {  
			                            alert("请填写正确的邮箱格式.如:ru@qq.com");  
			                            return false;  
			                        }
			                        else if(!isIDnumber(channelform.IDnumber.value))  
			                        {  
			                            alert("请输入18位合法的身份证号");  
			                            return false;  
			                        }
			                        else if(!isPhone(channelform.phone.value))  
			                        {  
			                            alert("请输入11位正确的手机号.如：13146031104");  
			                            return false;  
			                        }
			                        else if(!isPostcode(channelform.postcode.value))  
			                        {  
			                            alert("请输入正确的邮编.如100000");  
			                            return false;  
			                        }
			                        else if(channelform.address.value=="")  
			                        {  
			                            alert("请务必填写您的收货地址");  
			                            return false;  
			                        }
			                       
			                        return true;  
			                    } 
			                    function isName(str)          // 判断用户名格式是否正确
			                    {  
			                        var rx = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/;  
			                        return rx.test(str);  
			                    }  
			                      
			                    function isEmail(str)          // 判断是否为邮箱
			                    {  
			                        var rx = /^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;  
			                        return rx.test(str);  
			                    }
			                    function isIDnumber(str)          // 判断是否为身份证号
			                    {  
			                        var rx = /^\d{15}|\d{}18$/;  
			                        return rx.test(str);  
			                    }
			                    function isPhone(str)          // 判断是否为手机号
			                    {  
			                        var rx = /^1[34578]\d{9}$/;  
			                        return rx.test(str);  
			                    }
			                    function isPostcode(str)          // 判断是否为邮编
			                    {  
			                        var rx = /^[1-9][0-9]{5}$/;  
			                        return rx.test(str);  
			                    }
			                    function isAddress(str)          // 判断是否为邮编
			                    {  
			                        var rx = /^[1-9][0-9]{5}$/;  
			                        return rx.test(str);  
			                    }
				</script>
            </div>
            </div>
        </section>
        <!-- End: Content -->
        
        <!-- Start: Footer-->
        <footer class="footer">
            <p>Copyright &copy; 2017.Company name All rights reserved.</p>
        </footer>
        <!-- End: Footer -->
        
    </div>
    <!-- End: Main Content -->
    
    <!-- Javascript Files -->
    <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/jquery.pagination.js"></script>
	<script type="text/javascript" src="js/jquery.knob.min.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
</body>
</html>
